Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor credentials from error handling #94682

Merged
merged 19 commits into from
Sep 22, 2024

Conversation

gabrielcaires
Copy link
Contributor

@gabrielcaires gabrielcaires commented Sep 18, 2024

Related to #

Proposed Changes

Testing Instructions

Base:

  • Access any flow using the credential step (E.g site-migration/site-migration-credentials?from=[FROM]&siteSlug=[WP_COM_SITESLUG]&siteId=[WPCOM_SITE_ID]
  • Follow the above scenarios

Scenario 1: (Credentials - Required Fields)

  • Click on Continue without fill any field
  • Check if you can see errors on the required fields (User and password)

Scenario 2: (Credentials - Create)

  • Fill all fields with correct values
  • Click on Continue
  • Check if you are redirected to the next screen.

Scenario 3: (Backup file - Required Fields)

  • Click on Continue without fill any field
  • Check if you can see errors on the required fields (User and password)

Scenario 4: (Backup - Create)

  • Fill all fields with correct values
  • Click on Continue
  • Check if you are redirected to the next screen

NOTE: These and more scenarios are tested via this test suite

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

@gabrielcaires gabrielcaires changed the base branch from trunk to update/improve-credentials-tests September 18, 2024 19:10
@gabrielcaires gabrielcaires changed the title Update/improve credentials form code Refactor credentials from Sep 18, 2024
@matticbot
Copy link
Contributor

matticbot commented Sep 18, 2024

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • notifications
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug update/improve-credentials-form-code on your sandbox.

Base automatically changed from update/improve-credentials-tests to trunk September 19, 2024 09:34
@gabrielcaires gabrielcaires changed the base branch from trunk to update/improve-credentials-tests September 19, 2024 10:18
@gabrielcaires gabrielcaires changed the base branch from update/improve-credentials-tests to trunk September 19, 2024 10:22
@gabrielcaires gabrielcaires marked this pull request as ready for review September 19, 2024 11:15
@gabrielcaires gabrielcaires changed the title Refactor credentials from Refactor credentials from error handling Sep 19, 2024
@gabrielcaires gabrielcaires requested a review from a team September 19, 2024 11:36
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Sep 19, 2024
@gabrielcaires gabrielcaires changed the title Refactor credentials from error handling Refactor credentials from error handling + field names Sep 19, 2024
@gabrielcaires gabrielcaires changed the title Refactor credentials from error handling + field names Refactor credentials from error handling Sep 19, 2024
@gabrielcaires gabrielcaires self-assigned this Sep 19, 2024
import { useSiteMigrationCredentialsMutation } from './use-site-migration-credentials-mutation';

const mapApiError = ( error: any ) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this response transformation to reduce complexity

recordTracksEvent( 'calypso_site_migration_automated_request_error' );
},
} );
const serverSideError = useFormErrorMapping( error, variables );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All error logic is now parsed by this hook and returned on the serverSideError variable

clearErrors,
} = useForm< CredentialsFormData >( {
mode: 'onSubmit',
reValidateMode: 'onSubmit',
disabled: isPending,
defaultValues: {
siteAddress: importSiteQueryParam,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backend is waiting for a from_url, and the front is calling as siteAddress. It was causing constantly process of map values to show errors. I just removed it.

Copy link
Contributor

@Imran92 Imran92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Fixed some merge conflicts and some test failing on and off. Merging to unblock another ticket

<Controller
control={ control }
name="siteAddress"
name="from_url"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are switching to snake case here, but backupFileLocation is in camel case. Having two different cases for the form fields in the same form looks a bit confusing to me. WDYT about sticking to one of the cases for all form fields instead?

@Imran92 Imran92 merged commit e8a711e into trunk Sep 22, 2024
11 checks passed
@Imran92 Imran92 deleted the update/improve-credentials-form-code branch September 22, 2024 15:52
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants